import QtQuick 2.12
import QtQuick.Controls 1.4
import QtQuick.Controls 2.7
import QtQuick.Layouts 1.12

Page {
    id: page2
    visible: false


    header:Rectangle {
        height: 64
        color: "green"
        RowLayout {
            anchors.fill: parent
            Button {
                id: retbtn
                width: 60
                height: 48
                background: Item {

                }
                onClicked:  {
                    //page2.StackView.view.pop()
                    //console.log("stackView: " + stackView)
                    //console.log("page2.StackView.view: " + page2.StackView.view)
                    stackView.pop()
                }
                icon {
                    source: "../images/icon_back.png"
                    color: "white"
                    height: 36
                    width: 36
                }
            }

            Text {
                text: qsTr("用户管理")
                font.pixelSize: 22
            }
            Item {
                Layout.fillWidth: true
            }
            CurrentDateTime {
                Layout.rightMargin: 10
            }


        }
    }

    Button {
        id: addAuthor
        text: qsTr("添加授权人员")
        background:  Rectangle {
            color: "green"
        }
        anchors.right: parent.right
        anchors.topMargin: 20
        anchors.rightMargin: 20
        anchors.top: parent.top
        onClicked: {
            adminCheck.open()

        }

    }
    Component {
        id: cellDelegate
        Rectangle {
            color: "transparent"
            Text {
                text: styleData.value
                anchors.centerIn: parent

            }
            height: 48
        }
    }
    Component {
        id: timeCellDelegate
        Rectangle {
            color: "transparent"
            Text {
                text: String(styleData.value)
                anchors.centerIn: parent
            }
            height: 48
        }
    }

    Component {
        id: row_delegate
        Rectangle {
            height: 48
            color: {
                if(styleData.pressed)
                    return "#66b2ff"
                else if(styleData.row & 0x1)
                    return "#fff"
                else
                    return  "#eee"
            }
        }
    }
    Component {
        id: headerDlg
        Rectangle {
            height: 48
            color: "#ffffee"
            //border.width: 1
            //border.color: "#ccc"
            Text {
                text: qsTr(styleData.value)
                font.pixelSize: 16
                    anchors.centerIn: parent
                color: "green"
            }

        }
    }

    TableView {
        id: userview;
        headerDelegate: headerDlg
        anchors {
            top: addAuthor.bottom
            bottom: parent.bottom
            left: parent.left
            right: parent.right
            topMargin: 20
            //margins: 10
        }


        rowDelegate: row_delegate
        clip: true
        TableViewColumn {
            role: "RoleName"
            title: qsTr("身份");
            elideMode: Text.ElideMiddle

            delegate: cellDelegate
        }
        TableViewColumn {
            role: "UID"
            title: qsTr("编号");
            delegate: cellDelegate


        }
        TableViewColumn {
            role: "Name"
            title: qsTr("姓名");
            delegate: cellDelegate

        }
        TableViewColumn {
            role: "useradd_time"
            title: qsTr("添加时间");
            width: 300;
            delegate: timeCellDelegate
        }

    }

    Component.onCompleted:  {
        userview.model = Services.getUserModel();
    }
    Popup {
        id: adminCheck
        width: 600
        height: 320
        anchors.centerIn: Overlay.overlay
        padding: 0
        Rectangle {
            id: adminCheckHeader
            width: parent.width
            height: 48
            color: "green"
            Text {
                text: qsTr("管理员身份验证")
                anchors {
                    left: parent.left
                    leftMargin: 20
                    verticalCenter: parent.verticalCenter
                }
            }

        }
        ColumnLayout {
            anchors.top: adminCheckHeader.bottom
            anchors.bottom: parent.bottom
            width: parent.width
            spacing: 32
            RowLayout {
                Layout.topMargin: 20
                Layout.fillWidth: true
                height: 48
                Item {
                    Layout.fillWidth: true
                }
                Text {
                    text: qsTr("账号：")
                }
                Rectangle {
                    height: parent.height
                    width: 200
                    border {
                        color: "#eee"
                        width: 1
                    }
                    TextField {
                        height: parent.height
                        placeholderText: qsTr("请输入管理员账号")

                    }
                }
                Item {
                    Layout.fillWidth: true
                }
            }
            RowLayout {
                Layout.fillWidth: true
                height: 48
                Item {
                    Layout.fillWidth: true
                }

                Text {
                    text: qsTr("密码：")
                }
                Rectangle {
                    height: parent.height
                    width: 200
                    border {
                        color: "#ccc"
                        width: 1
                    }
                    TextField {
                        height: parent.height
                        placeholderText: qsTr("请输入密码")
                    }
                }
                Item {
                    Layout.fillWidth: true
                }
            }
            RowLayout {
                 Layout.fillWidth: true
                 height: 48
                Button {
                    text: qsTr("取消")
                    Layout.bottomMargin: 20
                    Layout.leftMargin: 20
                    onClicked: {
                        adminCheck.close()
                    }

                }
                Item {
                    Layout.fillWidth: true
                }
                Button {
                    background: Rectangle {
                        color: "green"

                    }
                    text: qsTr("确认")
                    Layout.rightMargin: 20
                    Layout.bottomMargin: 20
                    implicitWidth: 96
                }
            }

        }

    }

}
